﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using ARchGL.Platform.Configuration;
using ARchGL.Platform.Web;

namespace ARchGL.Platform.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class HostDbContextFactory : IDesignTimeDbContextFactory<HostDbContext>
    {
        public HostDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<HostDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.GetContentRootFolder(), addUserSecrets: true);

            HostDbContextConfigurer.Configure(builder, configuration.GetConnectionString(HostConsts.ConnectionStringName));

            return new HostDbContext(builder.Options);
        }
    }

    public class TenantDbContextFactory : IDesignTimeDbContextFactory<TenantDbContext>
    {
        public TenantDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<TenantDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.GetContentRootFolder(), addUserSecrets: true);

            TenantDbContextConfigurer.Configure(builder, configuration.GetConnectionString(TenantConsts.ConnectionStringName));

            return new TenantDbContext(builder.Options);
        }
    }

}